package com.yunshang.shoppingmall.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunshang.shoppingmall.entity.ProductApis;
import com.yunshang.shoppingmall.entity.UserRank;
import com.yunshang.shoppingmall.mapper.ProductApisMapper;
import com.yunshang.shoppingmall.mapper.UserRankMapper;
import com.yunshang.shoppingmall.service.ProductApisService;
import com.yunshang.shoppingmall.service.User.UserRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;



import java.util.*;

@Service("productApisService")
public class ProductApisServiceImpl implements ProductApisService {
    @Autowired
    ProductApisMapper productApisMapper;

    @Autowired
    UserRankMapper userRankMapper;


//    @Autowired
//    RedisTemplate redisTemplate;
//
//    @Autowired
//    StringRedisTemplate stringRedisTemplate;

    @Override
    public ProductApis selectProductById(int productId) {
        return productApisMapper.selectProductById(productId);
    }

//    @Cacheable(cacheNames = "selectProductByActiveSign")
    @Override
    public List<ProductApis> selectProductByActiveSign(int pageNum,int  pageSize,int activeSign) {
        PageHelper.startPage(pageNum,pageSize);
        List<ProductApis> productApisList= productApisMapper.selectProductByActiveSign(activeSign);
//        redisTemplate.opsForList().leftPush("selectProductByActiveSign",productApisList);
       return productApisList;
    }
    @Cacheable(cacheNames = "productApisListByProductName")
    @Override
    public List<ProductApis> selectProductByProductName(String productName) {
       List<ProductApis> productApisList= productApisMapper.selectProductByProductName(productName);
        //redisTemplate.opsForList().leftPush("productApisListByProductName", productApisList);
        return productApisList;
    }

    @Override
    public List<ProductApis> selectProductBySJClassifyId(int sjClassifyId) {
        return productApisMapper.selectProductBySJClassifyId(sjClassifyId);
    }


    //实际支付----优惠后最低价
    public  double  getMinyhPrice(double proPrice,double productCost,double opratorCost,double coupon,double yzDianzhu,double commission){

        //会员节省
        double hyJShengs=getHyJSheng(proPrice,productCost,opratorCost,coupon,yzDianzhu,commission);
        //最低优惠价格
        double minyhPrice=proPrice-coupon-yzDianzhu-hyJShengs;
        return  minyhPrice;
    }

    //会员节省
    public double getHyJSheng(double proPrice,double productCost,double opratorCost,double coupon,double yzDianzhu,double commission){
        double hyJSheng=0.00;
        //最低利润
        double minLiRun=getMinLiRun(proPrice,productCost,opratorCost, coupon, yzDianzhu);
        hyJSheng=minLiRun*commission/100;
        return hyJSheng;
    }

    //最低利润值
    public double  getMinLiRun(double proPrice,double productCost,double opratorCost,double coupon,double yzDianzhu){

            double minLiRun=proPrice-productCost-opratorCost-coupon-yzDianzhu;
        return minLiRun;
    }

    //推荐提成(分享赚)
    public double getFenXiangZhuan(double proPrice,double productCost,double opratorCost,double coupon,double yzDianzhu,double YZDZcommission,double HYcommission){

        //最低利润
       double minLiRun= getMinLiRun(proPrice,productCost,opratorCost, coupon, yzDianzhu);

        double fenXiangZhuan=minLiRun*YZDZcommission/100-minLiRun*HYcommission/100;
        return fenXiangZhuan;
    }

}
